<?php
    include APPLICATION_PATH . '/application/views/head.phtml';
    include APPLICATION_PATH . '/application/views/top.phtml';
    include APPLICATION_PATH . '/application/views/left.phtml';
?>
<!-- <script src="/public/pagejs/logs_push.js"></script> -->
<!-- <script src="/public/js/jquery-migrate-1.2.1.min.js" type="text/javascript"></script> -->
<div id="thispage" data-id="62"></div>
		<!-- BEGIN PAGE -->

		<div class="page-content">

			<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->

			<div id="portlet-config" class="modal hide">

				<div class="modal-header">

					<button data-dismiss="modal" class="close" type="button"></button>

					<h3>portlet Settings</h3>

				</div>

				<div class="modal-body">

					<p>Here will be a configuration form</p>

				</div>

			</div>

			<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->

			<!-- BEGIN PAGE CONTAINER-->        

			<div class="container-fluid">

				<!-- BEGIN PAGE HEADER-->

				<div class="row-fluid">

					<div class="span12">

						<!-- BEGIN STYLE CUSTOMIZER -->

						<div class="color-panel hidden-phone">

							<!-- <div class="color-mode-icons icon-color"></div> -->

							<div class="color-mode-icons icon-color-close"></div>

							<div class="color-mode">

								<p>THEME COLOR</p>

								<ul class="inline">

									<li class="color-black current color-default" data-style="default"></li>

									<li class="color-blue" data-style="blue"></li>

									<li class="color-brown" data-style="brown"></li>

									<li class="color-purple" data-style="purple"></li>

									<li class="color-grey" data-style="grey"></li>

									<li class="color-white color-light" data-style="light"></li>

								</ul>

								<label>

									<span>Layout</span>

									<select class="layout-option m-wrap small">

										<option value="fluid" selected>Fluid</option>

										<option value="boxed">Boxed</option>

									</select>

								</label>

								<label>

									<span>Header</span>

									<select class="header-option m-wrap small">

										<option value="fixed" selected>Fixed</option>

										<option value="default">Default</option>

									</select>

								</label>

								<label>

									<span>Sidebar</span>

									<select class="sidebar-option m-wrap small">

										<option value="fixed">Fixed</option>

										<option value="default" selected>Default</option>

									</select>

								</label>

								<label>

									<span>Footer</span>

									<select class="footer-option m-wrap small">

										<option value="fixed">Fixed</option>

										<option value="default" selected>Default</option>

									</select>

								</label>

							</div>

						</div>

						<!-- END BEGIN STYLE CUSTOMIZER -->  

						<!-- BEGIN PAGE TITLE & BREADCRUMB-->

						<h3 class="page-title">

							日志管理

						</h3>

						<ul class="breadcrumb">

							<li>

								<i class="icon-home"></i>

								<span>当前位置：</span>
								<span>首页</span>

								<i class="icon-angle-right"></i>

							</li>

							<li>

								<span>日志管理</span>

								<i class="icon-angle-right"></i>

							</li>

							<li><span>推送日志</span></li>

						</ul>

						<div class="control-group clearfix">

                            <label class="control-label" style="float:left; line-height: 28px;">用户：</label>

                            <div class="controls" style="float:left;">
                    
                                <select class="small m-wrap" tabindex="1" id="type_select" >
                                    <option value="0" class="type" >选择推送的用户</option>
                  <?php 

                    foreach ($user_info as $key => $value) {
                        echo <<<EOF
                             <option value="{$value['user_id']}" class="type" data-id="{$value['user_id']}">{$value['realname']}</option>

EOF;
                    }
                                  
                  ?>
                                </select>

                            </div>
                            <label class="control-label" style="float:left; line-height: 28px; margin-left: 50px;">推送时间：</label>

                            <div class="controls" style="float:left;">

                                <label class="checkbox">

                                <div class="controls">
                                            
                                   <input placeholder="请输入日期" class="laydate-icon" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" id="push_time_input" name="push_time_input" value="请输入日期">

                                </div>

                                </label>

                                

                            </div>

						<!-- END PAGE TITLE & BREADCRUMB-->

					</div>

				</div>

				<!-- END PAGE HEADER-->

				<!-- BEGIN PAGE CONTENT-->

				<div class="row-fluid">

					<div class="span6 responsive" data-tablet="span12 fix-offset" data-desktop="span6" style="width:100%;">

						<!-- BEGIN EXAMPLE TABLE PORTLET-->

						<div class="portlet box grey">

							<div class="portlet-title">

								<div class="caption"><i class="icon-user"></i>推送日志</div>

								<div class="actions controls">

<!--									<a href="#modal_add" data-toggle="modal" data-target="#modal_add" class="btn blue"><i class="icon-pencil"></i> 添加</a>-->
									<!--<a href="/Index/Authority/add" class="btn blue"><i class="icon-pencil"></i> 添加</a>-->

								</div>

							</div>

							<div class="portlet-body">

								<table class="table table-striped table-bordered table-hover" id="current_table">

									<thead>

										<tr>
											
											<th>推送文章</th>
											<th>推送网站</th>
											<th>推送栏目</th>
											<th>推送人</th>
											<th>推送时间</th>
											<th>推送状态</th>
<!--											<th>加入时间</th>-->
<!--											<th>操作</th>-->
										</tr>

									</thead>

									<tbody id="tbody">
<?php
    foreach ($pushlogs_info as $k => $v) {
        $style = (0 == ($k % 2)) ? 'odd' : 'even';
        echo <<< EOF
										<tr class="{$style} gradeX">

											<td>{$v['article_title']}</td>
											<td>{$v['sitename']}</td>
											<td>{$v['catname']}</td>
											<td>{$v['username']}</td>
											<td>{$v['push_time']}</td>
											<td>{$v['article_status']}</td>

										</tr>
EOF;
    }
?>
									</tbody>
                </table>
                 <div id="pages">
<?php
    if($pushlogs_info[0]['rows']/$pushlogs_info[0]['every_page']<=1)
        {
            
        }
        else
        {
            print_r($allpage);
        }
?>
</div>

							</div>

						</div>
                        
                        		<div id="modal_add" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">

									<div class="modal-header">

										<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

										<h3 id="myModalLabel3">添加推送日志</h3>

									</div>

									<div class="modal-body">

										<form action="#" id="form_user_add" method="post" class="form-horizontal">

											<div class="control-group">

												<label class="control-label">推送文章</label>

												<div class="controls">
												<select id="article" name="article">
													<?php
													foreach($article_info as $val)
													{
														echo '<option value="';
														echo $val['article_id'] ;
														echo '">';
														echo $val['title'];
														echo "</option>";
													}
													?>

												</select>
												</div>

											</div>

											<div class="control-group">

												<label class="control-label">推送人</label>

												<div class="controls">
													<select id="pusher" name="pusher">
														<?php
														foreach($user_info as $val)
														{
															echo '<option value="';
															echo $val['user_id'] ;
															echo '">';
															echo $val['username'];
															echo "</option>";
														}
														?>

													</select>

												</div>

											</div>
											
                                            <div class="control-group">

												<label class="control-label">创建时间</label>

												<div class="controls">

													<input placeholder="请输入日期" class="laydate-icon" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  name="date">

												</div>

											</div>
                                            
												<div class="control-group">

												<label class="control-label">推送状态</label>

												<div class="controls">

													<select id="status">
														<option value="1">已推送</option>
														<option value="0">未推送</option>
													</select>
												</div>
											</div>
                                            
											

-->
										</form>

									</div>

									<div class="modal-footer">

										<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>

										<button class="btn green btn-primary" id="submit_form" data-dismiss="modal" >提交</button>

									</div>

								</div>

								<div id="modal_edit" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">

									<div class="modal-header">

										<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

										<h3 id="myModalLabel3">编辑推送日志</h3>

									</div>

									<div class="modal-body">

										<form action="#" id="form_user_edit" method="post" class="form-horizontal">

											<div class="control-group">

												<label class="control-label">推送文章</label>

												<div class="controls">

													<select id="article" name="article">
														<?php
														foreach($article_info as $val)
														{
															echo '<option value="';
															echo $val['article_id'] ;
															echo '">';
															echo $val['title'];
															echo "</option>";
														}
														?>
													</select>

												</div>

											</div>

											<div class="control-group">

												<label class="control-label">推送人</label>

												<div class="controls">

													<select id="pusher" name="pusher">
														<?php
														foreach($user_info as $val)
														{
															echo '<option value="';
															echo $val['user_id'] ;
															echo '">';
															echo $val['username'];
															echo "</option>";
														}
														?>

													</select>

												</div>

											</div>
											                                            
                                            <div class="control-group">

												<label class="control-label">创建时间</label>

												<div class="controls">

													<!-- <input type="text" class="colorpicker-default m-wrap" name="create_time" value="">
													 -->
													<input placeholder="请输入日期" class="laydate-icon" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  name="date">

												</div>

											</div>
                                            
											<div class="control-group">

												<label class="control-label">推送状态</label>

												<div class="controls">

													<select id="push">
														<option value="1">已推送</option>
														<option value="0">未推送</option>
													</select>

												</div>

											</div>
                                            
										</form>

									</div>

									<div class="modal-footer">

										<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>

										<button class="btn green btn-primary" id="submitEdit" data-dismiss="modal" >提交</button>
                                        
									</div>

								</div>

						<!-- END EXAMPLE TABLE PORTLET-->

					</div>

				</div>

				<!-- END PAGE CONTENT-->

			</div>

			<!-- END PAGE CONTAINER-->

		</div>
<script>
$(document).ready(function() {
	$(document).on('click', '#page_next,#page_prev,#page_index,#page_end', function() {
		var urlOld = $(this).attr('href'),
			urlArr = urlOld.split("/");
		urlId = urlArr[urlArr.length - 1];
		$.ajax({
			type: 'POST',
			url: '/Logs/pushPage/page/' + urlId,
			data: urlId,
			success: function(data) {
				var data = $.parseJSON(data);

				$('#tbody').html('');
				var id = '';

				$.each(data, function(k, v) {

					//id = v['title'];

					$('#tbody').append($('<tr class="gradeX"><td>' + v['article_title'] + '</td><td>' + v['sitename'] + '</td><td>' + v['catname'] + '</td><td>' + v['username'] + '</td><td>' + v['push_time'] + '</td><td>' + v['article_status'] + '</td></tr>'));



				});


			}

		});
		$.ajax({
			type: 'POST',
			url: '/Logs/pushCurrentPage/page/' + urlId,
			data: urlId,
			success: function(data) {
				console.log(data);
				$('#pages').html(data);
				$('#pages').ready(function() {
					nextBtn = $('#page_next');
				});
			}

		});
		return false;
	});


	$("#push_time_input").on('click', function(){
		//var user_id = $("#type_select").val();
		//var date = $("#push_time_input").val().split(" ")[0];
		$(".laydate_box tr td").each(function(){
			var user_id = $("#type_select").val();
			$(this).click(function(){
				if(/\d{2}/g.test($(this).attr("d")) ==false) {
					var date = $(this).attr("y")+"-"+$(this).attr("m")+"-0"+$(this).attr("d");
				}
				else{
					var date = $(this).attr("y")+"-"+$(this).attr("m")+"-"+$(this).attr("d");
				}
				
				$.ajax({
					type: 'POST',
					url: '/logs/pushInfo' ,
					data: {"date":date,"user_id":user_id},
					success: function(data) {
						$('#tbody').html('');
						$('#pages').html('');
						var id = '';
		$('#tbody').siblings().html('<tr><th>推送网站</th><th>推送人</th><th>最后推送时间</th></tr>');
				$.each(data, function(k, v) {
					$('#tbody').append($('<tr class="gradeX"><td>' + v['site_name'] + '</td><td>' + v['user_name'] + '</td><td>' + v['pushLastTime'] + '</td</tr>'));
				});
					}
				});
				return false;
			});
		});
	});

});
</script>


    <!-- END PAGE -->
<?php
    include APPLICATION_PATH . '/application/views/foot.phtml';
?>
